# models/charging_station.py
from pydantic import BaseModel, Field, BeforeValidator
from typing import Annotated, Optional, List
from datetime import datetime
from decimal import Decimal
import uuid # ✅ 确保导入 uuid

# 定义一个预处理函数，将 UUID 转换为字符串
def convert_uuid_to_str(value):
    if isinstance(value, uuid.UUID):
        return str(value)
    return value

# 使用 Annotated 和 BeforeValidator
class ChargingStationDB(BaseModel):
    # ✅ 使用 Annotated 包装 str，并应用 BeforeValidator
    id: Annotated[str, BeforeValidator(convert_uuid_to_str)] = Field(..., description="唯一标识符")
    amap_id: str = Field(..., description="高德地图ID")
    name: str = Field(..., description="充电站名称")
    address: str = Field(..., description="详细地址")
    tel: Optional[str] = Field(None, description="联系电话")
    province: str = Field(..., description="省份")
    city: str = Field(..., description="城市")
    district: Optional[str] = Field(None, description="区县")
    business_area: Optional[str] = Field(None, description="商圈")
    operator: Optional[str] = Field(None, description="运营商")
    charger_type: Optional[str] = Field(None, description="充电桩类型")
    location: str = Field(..., description="经纬度 (WKT格式)")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")